home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / MACSHELL / MS1 / COMMANDS / ALIAS.C next >
Text File  |  1992-12-02  |  6KB  |  223 lines

  1. /*
  2.  *    MacShell Source File
  3.  *
  4.  *    Copyright (c) 1989, 1990, 1991, 1992  Suick Bay Technologies.  All rights reserved.
  5.  *
  6.  *
  7.  *    RESTRICTIONS ON MacShell program and source code.
  8.  *
  9.  *    Ñ╩MacShell¬ is a product of Suick Bay Technologies and is provided for
  10.  *    restricted use by the owner of the CDROM "Disk to the future II".
  11.  *
  12.  *    Ñ╩No permission is granted for any commercial use without the written
  13.  *    consent of the Suick Bay Technologies.
  14.  *
  15.  *    Ñ╩No permission is granted for any redistribution of any kind use without
  16.  *    the written consent of the Suick Bay Technologies.
  17.  *
  18.  *    Ñ╩Permission is granted to use this for any personal noncommercial use.
  19.  *
  20.  *    Ñ╩You may not distribute source or executable code at all, nor may you 
  21.  *    distribute it with or within a commercial product without the written
  22.  *    consent of the Suick Bay Technologies.  Please send modifications to 
  23.  *    the author for inclusion in updates to the program.  Thanks.
  24.  *
  25.  *
  26.  *    MacShell¬ IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  27.  *    WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  28.  *    PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
  29.  *
  30.  *    SUICK BAY TECHNOLOGIES SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  31.  *    INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY MACSHELL
  32.  *    OR ANY PART THEREOF. 
  33.  *
  34.  *    In no event will Suick Bay Technologies be liable for any lost revenue
  35.  *    or profits or other special, indirect and consequential damages, even if
  36.  *    Suick Bay Technologies has been advised of the possibility of such damages.
  37.  *
  38.  *    Suick Bay Technologies can be reached at:
  39.  *    
  40.  *    8768 Cottonwood lane
  41.  *    Maple Grove, MN 55369
  42.  *    Voice: (612) 425-7025
  43.  *    AppleLink: D5233
  44.  *    
  45.  *
  46.  *    No parts of this software may be reproduced or stored in a
  47.  *    retrieval system or transmitted in any form, or any means,
  48.  *    electronic, mechanical, photocopying, recording or otherwise,
  49.  *    without the prior written permission of Suick Bay Technologies.
  50.  *    
  51.  *    Spread the word and not the disk.
  52.  *    
  53.  *    SPK 020790    :    Initial
  54.  */
  55.   
  56. #include    "SystemPub.h"
  57. #include    "Proc.h"
  58. #include    "ShellPub.h"
  59. #include    "Path.h"
  60.  
  61. extern int16        appResFile;
  62.  
  63. /*******************************************************************/
  64.  
  65. void    DumpAlias( WHandle ShellWh, int16 ProcID, char *command )
  66. {
  67. char    alias[ 256 ];
  68. char    **ch  = GetShellResStr( command, ALSRES ),
  69.          *cp;
  70.         
  71.     if( ch )
  72.         {
  73.         CopyStr( *ch, alias );
  74.         PtoCstr( alias );
  75.         procPrintf( ShellWh, ProcID, "%s=%s\n", command, alias );
  76.         }
  77. }
  78.  
  79. /*******************************************************************/
  80.  
  81. void    DumpAllAlias( WHandle ShellWh, int16 ProcID )
  82. {
  83. ShellWindRec    **MyShell;
  84. int16            i, id;
  85. Handle            h;
  86. int32            num;
  87. char            name[ 256 ];
  88.  
  89.     MyShell = (ShellWindRec **) (**(ShellWh)).thing;
  90.  
  91.     UseResFile( appResFile );
  92.     i = Count1Resources( ALSRES );
  93.  
  94.     while( i )
  95.         {
  96.         h = GetIndResource( ALSRES, i );
  97.         GetResInfo( h, &id, &num, name );
  98.         PtoCstr( name );
  99.         DumpAlias( ShellWh, ProcID, name );
  100.         i--;
  101.         }
  102. }
  103.  
  104. /*******************************************************************/
  105.  
  106. Boolean        DoALIAS( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  107.                     char *string )
  108. {
  109. int16    i, index;
  110. char    alias[ 256 ], subst[ 256 ],
  111.         *cp, *vp;
  112.         
  113. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  114.  
  115.     switch( ProcToken )
  116.         {
  117.         case    PROC_INIT    :
  118.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  119.             break;
  120.  
  121.         case    PROC_TERM    :
  122.         case    PROC_BREAK    :
  123.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  124.             /* Turn ourself off */
  125.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  126.             break;
  127.             
  128.         case    PROC_STDIN    :
  129.             if( (**MyShell).Proc[ ProcID ].flags )
  130.                 {
  131.                 (**MyShell).Proc[ ProcID ].flags = FALSE;
  132.  
  133.                 if( (**MyShell).Proc[ ProcID ].argc == 1 )
  134.                     DumpAllAlias( ShellWh, ProcID );
  135.                 else
  136.                     {
  137.                     for( i = 1; i < (**MyShell).Proc[ ProcID ].argc; i++ )
  138.                         {
  139.                         index = (**MyShell).Proc[ ProcID ].argv[ i ];
  140.                         cp = &((**MyShell).Proc[ ProcID ].cmdline[ index ]);
  141.                         
  142.                         *alias = '\0';
  143.                         *subst = '\0';
  144.                         vp = alias;
  145.                         while( *vp = *cp )
  146.                             {
  147.                             if( *vp == '=' )
  148.                                 {
  149.                                 /* *vp++ = '\n';  */
  150.                                 *vp = '\0';
  151.                                 vp = subst;
  152.                                 cp++;
  153.                                 }
  154.                             else
  155.                                 {
  156.                                 vp++;
  157.                                 cp++;
  158.                                 }
  159.                             }
  160.                         
  161.                         if( *subst )
  162.                             {
  163.                             RemShellResStr( alias, ALSRES );
  164.                             AddShellResStr( alias, subst, ALSRES );
  165.                             }
  166.                         else
  167.                             DumpAlias( ShellWh, ProcID, alias );
  168.                         }
  169.                     }
  170.                 /* Tell the shell that we're done */
  171.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  172.                 
  173.                 /* Turn ourself off */
  174.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  175.                 return( FALSE );
  176.                 }
  177.         }
  178. }
  179.  
  180. /*******************************************************************/
  181.  
  182. Boolean        DoUNALIAS( int16 ProcToken, WHandle ShellWh, int16 ProcID,
  183.                 char *string )
  184. {
  185. int16            i, argc;
  186. char            argument[ 256 ];
  187. ShellWindRec    **MyShell = (ShellWindRec **) (**ShellWh).thing;
  188.  
  189.     switch( ProcToken )
  190.         {
  191.         case    PROC_INIT    :
  192.             (**MyShell).Proc[ ProcID ].flags = TRUE;
  193.             break;
  194.  
  195.         case    PROC_TERM    :
  196.         case    PROC_BREAK    :
  197.             SendOutToken( ShellWh, ProcID, PROC_BREAK );
  198.             /* Turn ourself off */
  199.             (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  200.             break;
  201.             
  202.         case    PROC_STDIN    :
  203.             if( (**MyShell).Proc[ ProcID ].flags )
  204.                 {
  205.                 (**MyShell).Proc[ ProcID ].flags = FALSE;
  206.                                 
  207.                 argc = (**MyShell).Proc[ ProcID ].argc;
  208.                 for( i = 1; i < argc; i++ )
  209.                     {
  210.                     GetArgv( ShellWh, ProcID, i, argument );
  211.                     RemShellResStr( argument, ALSRES );
  212.                     }
  213.  
  214.                 /* Tell the shell that we're done */
  215.                 SendOutToken(  ShellWh, ProcID, PROC_BREAK );
  216.                 
  217.                 /* Turn ourself off */
  218.                 (**MyShell).Proc[ ProcID ].ProcActive = FALSE;
  219.                 return( FALSE );
  220.                 }
  221.         }
  222. }
  223.